<?php

/*
 * 获取已加载的配置
 *
 * @param string $confName
 *
 * @return mixed $value
 */
function env($confName)
{
    $index = explode_without_space('.', $confName);

    return \fty\Config\Register::getInstance()->readConfigure($index);
}

/*
 * 分割字符串, 并去除空元素
 * 
 * @param string $separator
 * @param string $string
 *
 * @return array array_filter
 */
function explode_without_space($separator, $string)
{
    return array_filter(explode($separator, $string), function($val) {

        return $val != '';

    });
}

/*
 * 过滤数组 不包含某值
 *
 * @param array  $array
 * @param string $value
 *
 * @return array $array
 */
function array_without_value(array $array, $value)
{
    foreach ($array as $k => $v) {
        if ($v == $value) {
            unset($array[$k]);
        }
    }

    return array_values($array);
}

/*
 * 获取视图文件
 *
 * @param string $viewPath
 * @param array  $render
 *
 * @return view  $view
 */
function view($viewPath, $render = [])
{
    $viewDir  = $_SERVER['DOCUMENT_ROOT'] . '/../resources/views/';
    $viewPath = str_replace('.', '/', $viewPath);

    extract($render);

    require $viewDir . $viewPath . '.php';
}
